// mypage/myTeam/myTeam.js
var app=getApp();
var util=require("../../utils/util");
var my=require("../../api/my");

Page({
  /*页面的初始数据*/
  data: {
    navColor:'rgba(0,0,0,0)',
    title: "我的团队",
    moneyInfo: '',
    add_list: [{count:0,text:'今日新增'},{count:0,text:'昨日新增'},{count:0,text:'本月新增'},{count:0,text:'上月新增'}],
    fun_page: ["../teamBill/teamBill","../teamMember/teamMember","../tasteList/tasteList"],
    token: '',
    teamInfo: ''
  },
  /*生命周期函数--监听页面加载*/
  onLoad: function (options) {
    var that=this;
    that.setData({token:wx.getStorageSync('token')})
    that.get_team_money()
    that.get_team_count()
  },
  nav_go:function(e){
    var that=this,fun_page=that.data.fun_page;
    var index=e.currentTarget.dataset.index;
    wx.navigateTo({
      url: fun_page[index],
    })
  },
  get_team_money:function(){
    var that=this;
    my.teamMoney(that.data.token).then(res=>{
      var info=res.data.data;
      if(info){
        info.currentMonthSum=info.currentMonthSum>=10000?util.toThousands(util.toDecimal(info.currentMonthSum)):util.toDecimal(info.currentMonthSum)
        info.todaySum=info.todaySum>=10000?util.toThousands(util.toDecimal(info.todaySum)):util.toDecimal(info.todaySum)
        info.yesterdaySum=info.yesterdaySum>=10000?util.toThousands(util.toDecimal(info.yesterdaySum)):util.toDecimal(info.yesterdaySum)
        info.lastMonthSum=info.lastMonthSum>=10000?util.toThousands(util.toDecimal(info.lastMonthSum)):util.toDecimal(info.lastMonthSum)
      }else{
        info={currentMonthSum:0,todaySum:0,yesterdaySum:0,lastMonthSum:0}
      }
      that.setData({moneyInfo:info})
    })
  },
  get_team_count:function(){
    var that=this,add_list=that.data.add_list;
    my.newTeamCount(that.data.token).then(res=>{
      var info=res.data.data;
      add_list[0].count=info.todayNum
      add_list[1].count=info.yesterdayNum
      add_list[2].count=info.currentMonthNum
      add_list[3].count=info.lastMonthNum
      that.setData({teamInfo:info,add_list:add_list})
    })
  },
})